// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Point2DTests.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Numerics
{
    using System;

    using Microsoft.Robotics.Numerics;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Point2D unit tests. 
    /// </summary>
    [TestClass]
    public class Point2DTests
    {
        /// <summary>
        /// Tests if Point2DHoldsCorrectValuesWhenFieldsAreInitializedViaDefaultConstructor
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Point2DHoldsCorrectValuesWhenFieldsAreInitializedViaDefaultConstructor()
        {
            Point2D<double> t2 = new Point2D<double>(17, 23);
            Assert.IsTrue(t2.X == 17);
            Assert.IsTrue(t2.Y == 23);
        }

        /// <summary>
        /// Tests if Point2DCopyConstructorWorks 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Point2DCopyConstructorWorks()
        {
            Point2D<int> p1 = new Point2D<int>(17, 23);
            Point2D<int> p2 = new Point2D<int>(p1);
            Assert.IsTrue(p2.X == 17);
            Assert.IsTrue(p2.Y == 23);
        }

        /// <summary>
        /// Tests if EqualityHoldsWhenPointsAreIdenticalAndFailsOtherwise 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void EqualityHoldsWhenPointsAreIdenticalAndFailsOtherwise()
        {
            Point2D<double> p1 = new Point2D<double>(17, 23);
            Point2D<double> p2 = new Point2D<double>(17, 23);
            Point2D<double> p3 = new Point2D<double>(117, 23);
            Point2D<double> p4 = new Point2D<double>(17, 123);
            Assert.IsTrue(p1 == p2);
            Assert.IsTrue(p2 != p3);
            Assert.IsTrue(p2 != p4);
        }

        /// <summary>
        /// Test addition of a point and a vector.
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Point2DAdditionOperatorTest()
        {
            Point2D p1 = new Point2D(1, 3);
            Point2D p2 = new Point2D(10, 3);
            Point2D p3 = new Point2D(1, 30);
            Point2D p4 = new Point2D(0, 0);

            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(1, 2);
            Vector2 v3 = new Vector2(-2, 1);
            Vector2 v4 = new Vector2(-4, -2);

            Assert.AreEqual(new Point2D(1, 3), p1 + v1);
            Assert.AreEqual(new Point2D(11, 5), p2 + v2);
            Assert.AreEqual(new Point2D(-1, 31), p3 + v3);
            Assert.AreEqual(new Point2D(-4, -2), p4 + v4);
        }

        /// <summary>
        /// Test subtracting two points.
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void SubtractPointFromPoint2DTest()
        {
            Point2D p1 = new Point2D(1, 3);
            Point2D p2 = new Point2D(10, 3);
            Point2D p3 = new Point2D(1, 30);
            Point2D p4 = new Point2D(0, 0);

            Point2D p5 = new Point2D(0, 0);
            Point2D p6 = new Point2D(1, 2);
            Point2D p7 = new Point2D(-2, 1);
            Point2D p8 = new Point2D(-4, -2);

            Assert.AreEqual(new Vector2(1, 3), p1 - p5);
            Assert.AreEqual(new Vector2(9, 1), p2 - p6);
            Assert.AreEqual(new Vector2(3, 29), p3 - p7);
            Assert.AreEqual(new Vector2(4, 2), p4 - p8);
        }

        /// <summary>
        /// Test subtracting a vector from a point
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void SubtractVectorFromPoint2DTest()
        {
            Point2D p1 = new Point2D(1, 3);
            Point2D p2 = new Point2D(10, 3);
            Point2D p3 = new Point2D(1, 30);
            Point2D p4 = new Point2D(0, 0);

            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(1, 2);
            Vector2 v3 = new Vector2(-2, 1);
            Vector2 v4 = new Vector2(-4, -2);

            Assert.AreEqual(new Point2D(1, 3), p1 - v1);
            Assert.AreEqual(new Point2D(9, 1), p2 - v2);
            Assert.AreEqual(new Point2D(3, 29), p3 - v3);
            Assert.AreEqual(new Point2D(4, 2), p4 - v4);
        }
    }
}
